home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSUNIX.C < prev    next >
C/C++ Source or Header  |  1993-07-07  |  4KB  |  151 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bsunix.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code for run-time library functions which are not
  25. //    found on SCO UNIX.
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <bs.h>
  46. #if OS_UNIX
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. //   Description:    Replacement for memcmp function
  51. //    Parameters:    See C RTL docs
  52. //       Returns:    See C RTL docs
  53. //----------------------------------------------------------------------------
  54. int memcmp(const void *__s1, const void *__s2, size_t __n)
  55. {
  56.     PBYTE pb1 = (PBYTE)__s1;
  57.     PBYTE pb2 = (PBYTE)__s2;
  58.  
  59.     for ( ; __n; --__n, ++pb1, ++pb2)
  60.         if (*pb1 > *pb2)
  61.             return 1;
  62.         else if (*pb1 < *pb2)
  63.             return -1;
  64.  
  65.     return 0;
  66. }
  67.  
  68.  
  69. //----------------------------------------------------------------------------
  70. //   Description:    Replacement for stricmp function
  71. //    Parameters:    See C RTL docs
  72. //       Returns:    See C RTL docs
  73. //----------------------------------------------------------------------------
  74. int stricmp(const char *s1, const char *s2)
  75. {
  76.     for (; ; s1++, s2++)
  77.         {
  78.         CHAR ch1 = (CHAR)toupper(*s1);
  79.         CHAR ch2 = (CHAR)toupper(*s2);
  80.  
  81.         if (ch1 > ch2)
  82.             return 1;
  83.         else if (ch1 < ch2)
  84.             return -1;
  85.  
  86.         if (ch1 == '\0' && ch2 == '\0')
  87.             return 0;
  88.         }
  89.     return 0;
  90. }
  91.  
  92.  
  93. //----------------------------------------------------------------------------
  94. //   Description:    Replacement for strnicmp function
  95. //    Parameters:    See C RTL docs
  96. //       Returns:    See C RTL docs
  97. //----------------------------------------------------------------------------
  98. char *strlwr(char *s1)
  99. {
  100.     char *s2 = s1;
  101.  
  102.     for (; *s1; s1++)
  103.         *s1 = (CHAR)tolower(*s1);
  104.  
  105.     return s2;
  106. }
  107.  
  108.  
  109. //----------------------------------------------------------------------------
  110. //   Description:    Replacement for strnicmp function
  111. //    Parameters:    See C RTL docs
  112. //       Returns:    See C RTL docs
  113. //----------------------------------------------------------------------------
  114. int strnicmp(const char *s1, const char *s2, size_t maxlen)
  115. {
  116.     for (; maxlen; maxlen--, s1++, s2++)
  117.         {
  118.         CHAR ch1 = (CHAR)toupper(*s1);
  119.         CHAR ch2 = (CHAR)toupper(*s2);
  120.  
  121.         if (ch1 > ch2)
  122.             return 1;
  123.         else if (ch1 < ch2)
  124.             return -1;
  125.  
  126.         if (ch1 == '\0' && ch2 == '\0')
  127.             return 0;
  128.         }
  129.     return 0;
  130. }
  131.  
  132.  
  133. //----------------------------------------------------------------------------
  134. //   Description:    Replacement for strnicmp function
  135. //    Parameters:    See C RTL docs
  136. //       Returns:    See C RTL docs
  137. //----------------------------------------------------------------------------
  138. char *strupr(char *s1)
  139. {
  140.     char *s2 = s1;
  141.  
  142.     for (; *s1; s1++)
  143.         *s1 = (CHAR)toupper(*s1);
  144.  
  145.     return s2;
  146. }
  147. //----------------------------------------------------------------------------
  148. //------------------------------- End of File --------------------------------
  149. //----------------------------------------------------------------------------
  150. #endif                                            // OS_UNIX
  151.